//
//  NSObject+Method.m
//  MengLiao
//
//  Created by xiuxin on 2022/7/14.
//  Copyright © 2022 BaseBusiness. All rights reserved.
//
//https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html
#import "NSObject+Method.h"
void hqAddMethod(id self,SEL _cmd){
    
}
@interface HQProxy : NSObject

@end

@implementation HQProxy
+ (instancetype)share{
    static dispatch_once_t onceToken;
    static HQProxy *_instanceManager = nil;
    dispatch_once(&onceToken, ^{
        _instanceManager = [[HQProxy alloc] init];
    });
    return _instanceManager;
}
- (void)addMethodWithSel:(SEL)aSelector{
    NSString *typeCode = [[NSString alloc] initWithFormat:@"v:%@",NSStringFromSelector(aSelector)];
    class_addMethod([HQProxy class],aSelector,(IMP)hqAddMethod,typeCode.UTF8String);
}
@end

@implementation NSObject (Method)
- (id)forwardingTargetForSelector:(SEL)aSelector{
    NSMethodSignature *signature  = [self methodSignatureForSelector:aSelector];
    if (signature) return nil;
    [[HQProxy share] addMethodWithSel:aSelector];
    return [HQProxy share];
}

@end
